package com.buba.record.service.impl;

import com.buba.pojo.other.Drugs;
import com.buba.pojo.record.DrugRecord;
import com.buba.pojo.record.Record;
import com.buba.record.mapper.DrugRecordMapper;
import com.buba.record.mapper.RecordMapper;
import com.buba.record.service.DrugRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.buba.record.vo.DrugRecordVv;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.*;

/**
 * <p>
 * 药品记录表 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2022-06-09
 */
@Service
@Slf4j
public class DrugRecordServiceImpl extends ServiceImpl<DrugRecordMapper, DrugRecord> implements DrugRecordService {
    @Autowired
    private DrugRecordMapper drugRecordMapper;

    @Autowired
    private RecordMapper recordMapper;

    @Override
    public List<DrugRecordVv> drugRecordById(Integer id , String begin , String end) {
        return drugRecordMapper.drugRecordById(id , begin , end);
    }

    @Override
    public DrugRecordVv drugMesById(Integer id) {
        return drugRecordMapper.drugMesById(id);
    }

    @Override
    public List<DrugRecordVv> drugPatientById(Integer id) {
        return drugRecordMapper.drugPatientById(id);
    }

    @Override
    public List<DrugRecordVv> patientRecordById(Integer id , String begin , String end) {
        return drugRecordMapper.patientRecordById(id , begin , end);
    }

    @Override
    public Drugs getByIddrugs(Integer id) {
        return drugRecordMapper.getByIddrugs(id);
    }

    @Override
    public boolean adddrugRecord(DrugRecordVv drugRecordVoo) {
        return drugRecordMapper.adddrugRecord(drugRecordVoo);
    }



    @Override
    public List<DrugRecordVv> pantPayRecor(Integer id) {
        log.info("pantPayRecorId::"+id);
        return drugRecordMapper.pantPayRecor(id);
    }

    @Override
    public DrugRecordVv payDetail(Integer id) {
        return drugRecordMapper.payDetail(id);
    }

    @Override
    public int payment(Integer id, Integer cardId) {
        DrugRecord drugRecord = baseMapper.selectById(id);

        Record record = new Record();
        record.setInpatientId(Integer.valueOf(drugRecord.getHospitalMark()));
        record.setPatientId(drugRecord.getPatientId());
        record.setDrugRecordSerialNumber(drugRecord.getSerialNumber());
        record.setRechargeExplain("药品花费");
        record.setCampusId(drugRecord.getCampusId());
        record.setMoney(drugRecord.getPrice());
        record.setDoctorId(drugRecord.getDoctorId());
        record.setDivisionTypeId(drugRecord.getOutpatientId());
        record.setPatientcardDi(cardId);
        Calendar calendar = Calendar.getInstance();//获取时间
        record.setCreationTime(calendar.getTime());
        record.setModificationTime(calendar.getTime());

        int insert = recordMapper.insert(record);

        return insert;
    }

}
